import { reqCategoryList, reqBannerList,reqFloorList } from '@/api'

const state = {
    categoryList: [],
    bannerList: [],
    floorList:[]
}

const mutations = {
    CATEGORY_LIST(state, categoryList) {
        state.categoryList = categoryList
    },

    BANNER_LIST(state, bannerList) {
        state.bannerList = bannerList
    },
    FLOOR_LIST(state, floorList){
        state.floorList = floorList
    }
}

const actions = {
    // 获取首页三级分类数据
    async getCategoryList({ commit }) {
        const res = await reqCategoryList()
        if (res.code !== 200) return console.log('请求首页三级分类失败')
        commit('CATEGORY_LIST', res.data)
    },

    // 获取首页轮播图数据
    async getBannerList({ commit }) {
        const res = await reqBannerList()
        if (res.code !== 200) return console.log('请求首页轮播图失败')
        commit('BANNER_LIST', res.data)
    },

    //获取商品楼层数据
    async getFloorList({commit}){
        const res = await reqFloorList()
        if(res.code !== 200) return console.log('请求商品楼层数据失败')
        commit('FLOOR_LIST',res.data)
    }
}

const getters = {}

export default {
    state,
    mutations,
    actions,
    getters,
}
